package org.farms.algo;

public class StrategyPoint implements Comparable<StrategyPoint>{
	private int x;
	private int y;
	private int profit;
	private int danger;
	private boolean hasMine;
	private float rating;
	
	public int compareTo(StrategyPoint anotherPoint) {
		return (int)(anotherPoint.getRating() - this.getRating());
	}
	
	@Override
	public boolean equals (Object obj) {
		if (obj == this) {
			return true;
		}
		if (obj == null || obj.getClass() != this.getClass()) {
			return false;
		}
		
		StrategyPoint anotherPoint = (StrategyPoint)obj;
		return this.x == anotherPoint.x && this.y == anotherPoint.y;
	}

	public StrategyPoint(int x, int y, int profit, int danger, boolean hasMine) {
		this.setX(x);
		this.setY(y);
		this.setProfit(profit);
		this.setDanger(danger);
		this.setHasMine(hasMine);
		this.calcRating(profit, danger);
	}
	
	public int getCost() {
		if (this.danger == 0) {
			return 1;
		}
		if ((this.danger % 2) == 0) {
			return (this.danger / 2) * 7;
		} else {
			return ((this.danger + 1) / 2) * 7;
		}
	}
	
	public int getPigNumber() {
		if (this.danger == 0) {
			return 1;
		}
		if ((this.danger % 2) == 0) {
			return this.danger / 2;
		} else {
			return (this.danger + 1) / 2;
		}
	}
	
	public void calcRating(int profit, int danger) {
		this.rating = (float)profit / (float)getCost();
	}
	
	public void refreshRating() {
		this.rating = (float)profit / (float)getCost();
	}
	
	public float getRating() {
		return rating;
	}

	public int getProfit() {
		return profit;
	}

	public void setProfit(int profit) {
		this.profit = profit;
	}
	
	public void incrementProfit (int profit) {
		this.profit += profit;
	}

	public int getDanger() {
		return danger;
	}

	public void setDanger(int danger) {
		this.danger = danger;
	}
	
	public void incrementDanger(int danger) {
		this.danger += danger;
	}

	public boolean isHasMine() {
		return hasMine;
	}

	public void setHasMine(boolean hasMine) {
		this.hasMine = hasMine;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
}
